// 155.最小栈
package LeetcodeHot100;

import java.util.Deque;
import java.util.LinkedList;

public class Solution155 {

}

class MinStack {
    Deque<Integer> stack;
    Deque<Integer> min;

    public MinStack() {
        stack = new LinkedList<>();
        min = new LinkedList<>();
    }

    public void push(int val) {
        stack.push(val);
        if (min.isEmpty() || min.peek() > val)
            min.push(val);
        else {
            min.push(min.peek());
        }
    }

    public void pop() {
        stack.pop();
        min.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min.peek();
    }
}